  
##' Calculates ground radiation using the Bristow Campbell method
##'
##' Calculates ground radiation using the Bristow Campbell method
##' @param b Bristow Campbell beta coefficient
##' @param ClearSkyTransmissivity clear sky transmissivity
##' @param ExtraTerrestrialRadiation extra terrestrial radiation
##' @param SlopeAspectFactor  slope aspect factor
##' @param AirTemperatureDailyRange  air temp daily range
##' @param AirTemperatureMonthlyRange air temp monthly range
##' @return ground radiation 
##' @author James Long
##' @export 
BristowCampbellStrategy <- function(b,
                                    ClearSkyTransmissivity,
                                    ExtraTerrestrialRadiation,
                                    SlopeAspectFactor,
                                    AirTemperatureDailyRange,
                                    AirTemperatureMonthlyRange ) {
  b                          <- as.numeric(b)
  ClearSkyTransmissivity     <- as.numeric(ClearSkyTransmissivity)
  ExtraTerrestrialRadiation  <- as.numeric(ExtraTerrestrialRadiation)
  SlopeAspectFactor          <- as.numeric(SlopeAspectFactor)
  AirTemperatureDailyRange   <- as.numeric(AirTemperatureDailyRange)
  AirTemperatureMonthlyRange <- as.numeric(AirTemperatureMonthlyRange)
  
  rd <-  .jnew( "cra/clima/gsrad/RadData" )
  algo <- .jnew( "cra/clima/gsrad/GSRBristowCampbellStrategy" )
  bcParams <- .jnew( "cra/clima/gsrad/BristowCampbellParameters" )
  bcParams$setB(b)
  rd$setClearSkyTransmissivity( ClearSkyTransmissivity )
  rd$setExtraTerrestrialRadiation( ExtraTerrestrialRadiation )
  rd$setSlopeAspectFactor( SlopeAspectFactor )
  rd$setAirTemperatureDailyRange( AirTemperatureDailyRange )
  rd$setAirTemperatureMonthlyRange( AirTemperatureMonthlyRange )
  algo$setParameters( bcParams )
  gsr <- .jnew( "cra/clima/gsrad/GSRadContext",
         .jcast(algo, new.class = "cra/clima/core/interfaces/gsrad/IAGSRadStrategy" )
  	    )
  gsr$evaluate(rd)
  return( rd$getGlobalSolarRadiation() )
}


##' calculates extraterrestrial radiation for a given latitude on a given day
##'
##' calculates extraterrestrial radiation for a given latitude on a given day
##' @param latitude latitude on the earth in decimal degrees
##' @param day day of the year (1-365)
##' @return extra terrestrial radiation  
##' @author James Long
##' @export 
getETRadiation <- function( latitude, day) {
        day <- as.character( day )
	etRadStrat <- .jnew( "cra/clima/gsrad/ERExtraterrestrialRadiationStrategy" )
	rd <-  .jnew( "cra/clima/gsrad/RadData" )
	rd$setLatitude( latitude )
	rd$setCurrentDay( Integer$parseInt( day ) ) 
	etRadStrat$evaluate( rd )
	return( rd$getExtraTerrestrialRadiation() )
}


